home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / demos / OpenGL / tex_cube / unitsquare.c++ < prev    next >
C/C++ Source or Header  |  1996-11-11  |  5KB  |  179 lines

  1. /*
  2.  * (c) Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * ALL RIGHTS RESERVED
  4.  * Permission to use, copy, modify, and distribute this software for
  5.  * any purpose and without fee is hereby granted, provided that the above
  6.  * copyright notice appear in all copies and that both the copyright notice
  7.  * and this permission notice appear in supporting documentation, and that
  8.  * the name of Silicon Graphics, Inc. not be used in advertising
  9.  * or publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.
  11.  *
  12.  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  13.  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  14.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  15.  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
  16.  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  17.  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  18.  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  19.  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  20.  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
  21.  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  22.  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  23.  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  24.  *
  25.  * US Government Users Restricted Rights
  26.  * Use, duplication, or disclosure by the Government is subject to
  27.  * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  28.  * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  29.  * clause at DFARS 252.227-7013 and/or in similar or successor
  30.  * clauses in the FAR or the DOD or NASA FAR Supplement.
  31.  * Unpublished-- rights reserved under the copyright laws of the
  32.  * United States.  Contractor/manufacturer is Silicon Graphics,
  33.  * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
  34.  *
  35.  * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  36.  */
  37. #include "unitsquare.h"
  38.  
  39. #include <GL/gl.h>
  40.  
  41. static float vertices[][3] = {
  42.   {-1.0, -1.0, 0.0},
  43.   {0.0, -1.0, 0.0},
  44.   {0.0, 0.0, 0.0},
  45.   {-1.0, 0.0, 0.0},
  46.  
  47.   {0.0, -1.0, 0.0},
  48.   {1.0, -1.0, 0.0},
  49.   {1.0, 0.0, 0.0},
  50.   {0.0, 0.0, 0.0},
  51.  
  52.   {-1.0, 0.0, 0.0},
  53.   {0.0, 0.0, 0.0},
  54.   {0.0, 1.0, 0.0},
  55.   {-1.0, 1.0, 0.0},
  56.  
  57.   {0.0, 0.0, 0.0},
  58.   {1.0, 0.0, 0.0},
  59.   {1.0, 1.0, 0.0},
  60.   {0.0, 1.0, 0.0}
  61.  
  62. };
  63.  
  64. static float texcoord[][2] = {
  65.   {0.0, 0.0},
  66.   {0.5, 0.0},
  67.   {0.5, 0.5},
  68.   {0.0, 0.5},
  69.  
  70.   {0.5, 0.0},
  71.   {1.0, 0.0},
  72.   {1.0, 0.5},
  73.   {0.5, 0.5},
  74.  
  75.   {0.0, 0.5},
  76.   {0.5, 0.5},
  77.   {0.5, 1.0},
  78.   {0.0, 1.0},
  79.  
  80.   {0.5, 0.5},
  81.   {1.0, 0.5},
  82.   {1.0, 1.0},
  83.   {0.5, 1.0}
  84. };
  85.  
  86. unitsquare::unitsquare()
  87. {
  88. }
  89.  
  90. void unitsquare::open()
  91. {
  92. }
  93.  
  94. void unitsquare::draw()
  95. {
  96.   glBegin(GL_QUADS);
  97.  
  98.   glTexCoord2fv(texcoord[0]);
  99.   glVertex3fv(vertices[0]);
  100.   glTexCoord2fv(texcoord[1]);
  101.   glVertex3fv(vertices[1]);
  102.   glTexCoord2fv(texcoord[2]);
  103.   glVertex3fv(vertices[2]);
  104.   glTexCoord2fv(texcoord[3]);
  105.   glVertex3fv(vertices[3]); 
  106.  
  107.   glTexCoord2fv(texcoord[4]);
  108.   glVertex3fv(vertices[4]);
  109.   glTexCoord2fv(texcoord[5]);
  110.   glVertex3fv(vertices[5]);
  111.   glTexCoord2fv(texcoord[6]);
  112.   glVertex3fv(vertices[6]);
  113.   glTexCoord2fv(texcoord[7]);
  114.   glVertex3fv(vertices[7]); 
  115.  
  116.   glTexCoord2fv(texcoord[8]);
  117.   glVertex3fv(vertices[8]);
  118.   glTexCoord2fv(texcoord[9]);
  119.   glVertex3fv(vertices[9]);
  120.   glTexCoord2fv(texcoord[10]);
  121.   glVertex3fv(vertices[10]);
  122.   glTexCoord2fv(texcoord[11]);
  123.   glVertex3fv(vertices[11]); 
  124.  
  125.   glTexCoord2fv(texcoord[12]);
  126.   glVertex3fv(vertices[12]);
  127.   glTexCoord2fv(texcoord[13]);
  128.   glVertex3fv(vertices[13]);
  129.   glTexCoord2fv(texcoord[14]);
  130.   glVertex3fv(vertices[14]);
  131.   glTexCoord2fv(texcoord[15]);
  132.   glVertex3fv(vertices[15]); 
  133.  
  134.   glEnd();
  135. }
  136.  
  137. void unitsquare::draw_backwards()
  138. {
  139.   glBegin(GL_QUADS);
  140.  
  141.   glTexCoord2fv(texcoord[3]);
  142.   glVertex3fv(vertices[3]);
  143.   glTexCoord2fv(texcoord[2]);
  144.   glVertex3fv(vertices[2]);
  145.   glTexCoord2fv(texcoord[1]);
  146.   glVertex3fv(vertices[1]);
  147.   glTexCoord2fv(texcoord[0]);
  148.   glVertex3fv(vertices[0]); 
  149.  
  150.   glTexCoord2fv(texcoord[7]);
  151.   glVertex3fv(vertices[7]);
  152.   glTexCoord2fv(texcoord[6]);
  153.   glVertex3fv(vertices[6]);
  154.   glTexCoord2fv(texcoord[5]);
  155.   glVertex3fv(vertices[5]);
  156.   glTexCoord2fv(texcoord[4]);
  157.   glVertex3fv(vertices[4]); 
  158.  
  159.   glTexCoord2fv(texcoord[11]);
  160.   glVertex3fv(vertices[11]);
  161.   glTexCoord2fv(texcoord[10]);
  162.   glVertex3fv(vertices[10]);
  163.   glTexCoord2fv(texcoord[9]);
  164.   glVertex3fv(vertices[9]);
  165.   glTexCoord2fv(texcoord[8]);
  166.   glVertex3fv(vertices[8]); 
  167.  
  168.   glTexCoord2fv(texcoord[15]);
  169.   glVertex3fv(vertices[15]);
  170.   glTexCoord2fv(texcoord[14]);
  171.   glVertex3fv(vertices[14]);
  172.   glTexCoord2fv(texcoord[13]);
  173.   glVertex3fv(vertices[13]);
  174.   glTexCoord2fv(texcoord[12]);
  175.   glVertex3fv(vertices[12]); 
  176.  
  177.   glEnd();
  178. }
  179.